//
//  ShoppingCartViewController.m
//  share_business
//
//  Created by 吴于凌 on 2017/9/5.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "ShoppingCartViewController.h"
#import "ShoppingCartViewCell.h"
#import "ShoppingCartCountView.h"
#import "ShoppingDeleteView.h"
@interface ShoppingCartViewController ()<UITableViewDelegate,UITableViewDataSource,ShoppingCartCountViewDelegate,ShoppingDeleteViewDelegate>

@property (nonatomic,strong) UITableView *tableView ;
//结算按钮视图
@property (nonatomic,strong) ShoppingCartCountView *countView ;
//删除按钮视图
@property (nonatomic,strong) ShoppingDeleteView *deleteView ;

//是否正在编辑
@property (nonatomic,assign)BOOL isEditing ;
@end

@implementation ShoppingCartViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTableView];
    //结算界面
    self.countView = [[ShoppingCartCountView alloc]initWithFrame:CGRectMake(0, APPHEIGHT-64-44-64, APPWIDTH, 64)];
    self.countView.delegate = self ;
    [self.countView  setBorder:1 cornerRadius:0];
    [self.view addSubview:self.countView];
    
    //删除，全选界面
    self.deleteView = [[ShoppingDeleteView alloc]initWithFrame:CGRectMake(0, APPHEIGHT-64-44-64, APPWIDTH, 64)];
    self.deleteView.delegate = self;
    [self.deleteView setBorder:1 cornerRadius:0];
    self.deleteView.hidden = YES ;
    [self.view addSubview:self.deleteView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setTopBarTitle:@"购物车"];
    [self setTopBarTitleColor:[UIColor redColor]];
    [self topRightItemButton:nil image2:ImageNamed(@"home_message") title1:@"编辑" title2:@"消息"];
}


-(void)initTableView {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, APPWIDTH, APPHEIGHT ) style:UITableViewStyleGrouped];
    self.tableView.delegate = self ;
    self.tableView.dataSource = self ;
    //边距
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 15);
    //  tableview不显示没内容的cell
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    //滑动隐藏键盘
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.view addSubview:self.tableView];
}
#pragma mark tableview事件
//每项数据个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10 ;
}
//每项数据高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  160 ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01 ;
}
//一共多少项
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1 ;
}
//每一个cell视图
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ShoppingCartViewCell *cell = [ShoppingCartViewCell cellWithTableView:tableView];
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
}


-(void)goPayView{
    
}
-(void)chooseDeleteAll:(BOOL)isChooseAll{
    
}
 
-(void)right1Action:(UIButton *)btn{
    self.isEditing = !self.isEditing ;
    if (self.isEditing) {
        [btn setTitle:@"完成" forState:UIControlStateNormal];
        self.countView.hidden = YES;
        self.deleteView.hidden = NO ;
    }else {
        [btn setTitle:@"编辑" forState:UIControlStateNormal];
        self.countView.hidden = NO;
        self.deleteView.hidden =YES ;
    }
    [self topLeftItemButton:nil title:@"编辑"];
//    [self topRightItemButton:nil image2:ImageNamed(@"home_message") title1:@"编辑" title2:@"消息"];

}

@end
